<!-- 操作日志 -->
<template>
  <div>
    <ZgNewPage
      ref="page"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="200"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          :title="h.label"
        >
          <template slot-scope="record">
            {{ record[h.code] }}
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
export default {
  data () {
    return {
      pageTitle: '融资企业管理',
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: true,
        showHeaderConfig: false,
        showAttachBtn: false
      },
      conditions: [
        { code: 'birth', compType: '日期区间', label: '操作时间', defaultVal: ['', ''] },
        { code: 'name', compType: '单行文本', label: '姓名', defaultVal: '', extra: { placeholder: '请输入姓名' } },
        {
          code: 'name',
          compType: '单行文本',
          label: '操作名称',
          defaultVal: '',
          extra: { placeholder: '请输入操作名称' }
        }
      ],
      headers: [
        { code: '1', label: '账号', isShow: true, sort: 0 },
        { code: '2', label: '姓名', isShow: true, sort: 0 },
        { code: '3', label: '操作时间', isShow: true, sort: 0 },
        { code: '4', label: '操作名称', isShow: true, sort: 0 },
        { code: '5', label: 'IP', isShow: true, sort: 0 }
      ]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', 1: 'test', 2: '白', 3: '2025-01-01 16:16', 4: '搜索日志', 5: '172.168.39.203' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter (f, param) {},
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
